package com.ali.ttt.core.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Author : yuxl
 * @create 2024/7/3 4:22 PM
 */
@Slf4j
@Configuration
public class AsyncThreadExecutorConfig {
    /** 核心线程数 */
    private final int corePoolSize = 10;
    /** 最大线程数 */
    private final int maxPoolSize = 200;
    /** 队列数 */
    private final int queueCapacity = 10;

    @Bean("async-thread-pool")
    public ExecutorService testFxbDrawExecutor(){
        log.info("async-thread-pool 加载成功");
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(corePoolSize);
        executor.setMaxPoolSize(maxPoolSize);
        executor.setQueueCapacity(queueCapacity);
        executor.setThreadNamePrefix("async-thread-");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor.getThreadPoolExecutor();
    }
}
